<template>
	<view class="flex-ju-c height100vh flex-col">
		<button type="primary" @click="taplogin" :loading="loading">本机号码一键登录</button>
		<view class="mt20 flex-a-i size26 color999">
			<checkbox-group @change="checkboxChange">
				<checkbox style="transform:scale(0.7)" value="1" />
			</checkbox-group>
			我已阅读并同意<text @click="navto('agreement?xieyi=1')" class="color072C5F">《用户协议》</text><text @click="navto('agreement?xieyi=2')" class="color072C5F">《隐私政策》</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				loading:false,
				value:""
			}
		},
		methods: {
			taplogin(){
				if(this.value == 1){
					this.loading = true
					uni.preLogin({
						provider: 'univerify',
						success:()=>{
							uni.login({
								provider: 'univerify',
								univerifyStyle: {
							  },
								success:(res)=>{
								    uni.closeAuthView()
									
									res.authResult.cid = uni.getStorageSync('getui_cid')
									this.http.registerlongin(res.authResult).then(res => {
										uni.setStorageSync('user',res.data)
										
										this.http.setcid({
											id:res.data.id,
											cid:uni.getStorageSync('getui_cid')
										})
										
										console.log(res,"kkk")
										if(res.code == 0){
											uni.reLaunch({
												url:"/pages/index/index"
											})
										}
									}).catch(err=>{
										this.loading = false
										uni.showModal({
											content:JSON.stringify(err) 
										})
									  // 处理错误
									})
									
								},
								fail:(res)=>{  // 登录失败
									this.loading = false
									console.log(res)
								}
							})
						},
						fail:(res)=>{
							this.loading = false
							console.log(res)
							if(res.metadata){
								uni.showModal({
									content:res.metadata.msg
								})
							}else{
								uni.showModal({
									content:'网络连接失败'
								})
							}
						}
					})

					// uni.login({
					// 	provider: 'univerify',
					// 	univerifyStyle: {
					//     fullScreen: true
					//   }
					// })
					
					
				}else{
					uni.showToast({
						title:"请同意协议",
						icon:"none"
					})
				}
			},
			checkboxChange(e){
				this.value = e.detail.value[0]
			}
		}
	}
</script>

<style>

</style>
